package ui.swing.focus;

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

public class FocusDemo extends JFrame{

	private static final long serialVersionUID = 904588705736195418L;

	public FocusDemo() {
		super("FocusDemo");
		
		JPanel contentPane = (JPanel)getContentPane();
		contentPane.setBorder(new TitledBorder("Focus Cycle A"));
		contentPane.add(createContentPanel(), BorderLayout.NORTH);
		JDesktopPane desktop1 = new JDesktopPane();
		contentPane.add(desktop1, BorderLayout.CENTER);
		
		JInternalFrame internalFrame1 = new JInternalFrame("Focus Cycle B", true, true ,true, true);
		contentPane = (JPanel)internalFrame1.getContentPane();
		contentPane.add(createContentPanel(), BorderLayout.NORTH);
		JDesktopPane desktop2 = new JDesktopPane();
		contentPane.add(desktop2, BorderLayout.CENTER);
		desktop1.add(internalFrame1);
		internalFrame1.setBounds(20, 20, 500, 300);
		internalFrame1.show();
		
		JInternalFrame internalFrame2 = new JInternalFrame("Focus Cycle C", true, true ,true, true);
		contentPane = (JPanel)internalFrame2.getContentPane();
		contentPane.add(createContentPanel(), BorderLayout.NORTH);
		JDesktopPane desktop3 = new JDesktopPane();
		contentPane.add(desktop3, BorderLayout.CENTER);
		desktop2.add(internalFrame2);
		internalFrame2.setBounds(20, 20, 500, 300);
		internalFrame2.show();
	}
	
	protected JPanel createContentPanel() {
		JPanel panel = new JPanel();
		panel.add(new JButton("Button 1"));
		panel.add(new JButton("Button 2"));
		panel.add(new JTextField(10));
		return panel;
	}
	
	public static void main(String[] args) {
		FocusDemo frame = new FocusDemo();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setBounds(0, 0, 600, 450);
		frame.setVisible(true);
	}
}
